package br.com.threads;

class Contar implements Runnable{
	private Integer contador = 0;
	public void run(){
		try{
			for(int i = 0; i < 1; i++){
				contar();
				Thread.sleep(300);
			}
		}catch(InterruptedException e){}
	}
	public synchronized int contar(){
		for(int i = 0; i < 10; i ++){
			System.out.println("Contando: " + Thread.currentThread().getName() + i);
			contador++;
			try{
				Thread.sleep(3000);
			}catch(InterruptedException e){}
		}
		return contador;
	}
}
public class NovoContador {
	public static void main(String[] args) {
		Contar c = new Contar();
		Thread [] t = new Thread[10];
		for(int i = 0; i < t.length; i++){
			t[i]= new Thread(c);
			t[i].setName("Thread-> " + i + "-> ");
			t[i].start();
		}
	}
}
